package com.chongbangbang.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chongbangbang.pojo.VaccineType;
import com.chongbangbang.service.VaccineTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 基本信息之疫苗类型 前端控制器
 * </p>
 *
 * @author TP
 * @since 2022-03-16 15:20:38
 */
@RestController
@RequestMapping("/chong/else/vaccineType")
@Api(tags = "vaccine type", value = "基本信息之疫苗类型")
public class VaccineTypeController {

    private final VaccineTypeService vaccineTypeService;

    public VaccineTypeController(VaccineTypeService vaccineTypeService) {
        this.vaccineTypeService = vaccineTypeService;
    }

    @ApiOperation("查询所有")
    @RequestMapping(value = "", method = RequestMethod.GET)
    public List<VaccineType> get() {
        return vaccineTypeService.list();
    }

    @ApiOperation("查询特定类型宠物的所有疫苗信息")
    @RequestMapping(value = "/type", method = RequestMethod.GET)
    public List<VaccineType> getPetVaccination(String petType) {
        QueryWrapper<VaccineType> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("fit_pet", petType);
        return vaccineTypeService.list(queryWrapper);
    }


    @ApiOperation("根据ID查询")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public VaccineType getById(@PathVariable Integer id) {
        return vaccineTypeService.getById(id);
    }


    @ApiOperation("单个插入")
    @RequestMapping(value = "", method = RequestMethod.POST)
    public boolean post(VaccineType vaccineType) {
        return vaccineTypeService.save(vaccineType);
    }


    @ApiOperation("批量插入")
    @RequestMapping(value = "/_mcreate", method = RequestMethod.POST)
    public boolean postBatches(@ApiParam(value = "传ArrayList<VaccineType>") ArrayList<VaccineType> list) {
        return vaccineTypeService.saveBatch(list);
    }


    @ApiOperation("根据ID更新")
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public boolean putById(@ApiParam(name = "id", value = "id要单独传") @PathVariable("id") Integer id, VaccineType vaccineType) {
        return vaccineTypeService.updateById(vaccineType);
    }

    @ApiOperation("批量更新")
    @RequestMapping(value = "/_mupdate", method = RequestMethod.PUT)
    public boolean putBatches(@ApiParam(value = "传ArrayList<VaccineType>") ArrayList<VaccineType> list) {
        return vaccineTypeService.updateBatchById(list);
    }


    @ApiOperation("根据ID删除")
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public boolean deleteById(@PathVariable Integer id) {
        return vaccineTypeService.removeById(id);
    }

    @ApiOperation("根据ID批量删除")
    @RequestMapping(value = "/_mdelete", method = RequestMethod.DELETE)
    public boolean deleteById(@ApiParam(value = "传ArrayList<Integer>") ArrayList<Integer> list) {
        return vaccineTypeService.removeById(list);
    }

}
